package com.example.android.utils;

import java.util.List;

/**
 * @author songChen
 * @Description: 无意义语音识别
 * @date 2019/02/22
 */
public class EmptyAudioUtils {

    /**
     * @param shorts
     * @return  {@link EmptyAudioResult}
     * @author songChen
     */
    public static EmptyAudioResult notEmptyAudio(List<short[]> shorts) {
        int m = 0;
        int S = 0;
        for (short[] aShort : shorts) {
            for (short i : aShort) {
                m += Math.abs(i) < 30 ? 1 : 0;
            }
            S += aShort.length;
        }
        int k = (m * 100) / S;
        int s1 = 0;
        int s2 = 0;
        for (short[] aShort : shorts) {
            for (short i : aShort) {
                s1 += Math.abs(i) > 1000 ? 1 : 0;
                s2 += Math.abs(i) > 80 ? 1 : 0;
            }
        }
        double V1 = (double) s1 * 100 / (double) S;
        double V2 = (double) s2 * 100 / (double) S;
        boolean b ;
        if (k > 30) {
            b = V2 >= 11;
        } else {
            b = V1 >= 1;
        }

        EmptyAudioResult result = new EmptyAudioResult(b,k,s1,s2,V1,V2,S);
        return result;
    }
}
